<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>1-同源策略</title>
    <link rel="stylesheet" href="http://127.0.0.1:8081/static/css/a.css">
    <script src="http://127.0.0.1:8081/static/js/a.js"></script>
</head>

<body>
    <img src="http://127.0.0.1:8081/static/img/a.png" alt="">
    <button id="btn">发ajax请求</button>
    <script>
        document.querySelector('#btn').onclick = () => {
            const xhr = new XMLHttpRequest()
            xhr.open('GET', 'http://127.0.0.1:8081/origin-server')
            xhr.onreadystatechange = () => {
                if (xhr.readyState === 4) {
                    if (xhr.status >= 200 && xhr.status <=300) {
                        console.log(xhr.responseText)
                    }
                }

            }
            xhr.send()

        }
    </script>
</body>

</html>